from flask import Flask
from flask import request, render_template

from Util import Util
from database.UserDAO import User,UserDAO

app = Flask(__name__, template_folder="html")

@app.route("/")
def default():
    return render_template("login.html")

@app.route("/validate", methods=["GET", "POST"])
def validate():
    username_ = request.form.get("username")
    password_ = request.form.get("password")
    user_dao = UserDAO()
    if user_dao.checkUser(username_, password_):
        return "success"
    else:
        return "failed"

if __name__ == "__main__":
    passwd = Util.generate_random_digi_string(2)+Util.generate_random_char_string(2)
    # print("password is: " + passwd)
    Util.cert = Util.hash(passwd)
    app.run(host="0.0.0.0", port=8000, debug=False)